const mongoUtil = require("../utils/mongo_util")

function addData(TvObj,collectionName,callback) {
    mongoUtil.getCollection(collectionName).then(collection => {
        collection.find({
            'doubanId': TvObj.doubanId
        }).toArray(function (err, result) {
            if (result.length > 0) {
                callback({
                    msg: "已存在"
                }, result)
                return
            }
            mongoUtil.getCollection(collectionName).then(collection => {
                collection.insertOne(TvObj, function (err, res) {
                    callback(err, res)
                });
            })
        })
    })
}
module.exports={
    addData
}